/* =========================================================
 * iquick_init.js
 * =========================================================
 * iQuick 系统初始化脚本
 *
 * ========================================================= */

// 通用操作失败提示
function sys_show_error(id,msg)
{
	$(id).html( "<div class=\"alert alert-danger\">"+ msg +"</i></div>" );
	return false;
}

// 通用操作成功提示
function sys_show_success(id,msg,jump)
{
	$(id).html( "<div class=\"alert alert-success\"><i class=\"picons-16-basic1-136\"></i>"+ msg +"</div>" );
	if(jump == false) { return false; }
	else
	{
		$(location).attr('href',jump);
	}
}

// 通用操作中提示
function sys_show_waitting(id)
{
	$(id).html( "<center><img src=\"/images/v3.iquicksample.com/iquick_waitting.gif\"></center>" );
	return false;
}

//useage sample
$(function() {

	//初始化变量

	//用户登录
	$("#submit_btn").click(function() {
		var login_credential = "username=" + $( "#user_login" ).val() + "&password=" + $( "#user_password" ).val();
		sys_show_waitting("#login_status");

		$.ajax({
			url: "/sys/user/sign_in/",
			type: "POST",
			data: login_credential,
			error: function(){
				 sys_show_error("#login_status","Error.");
			},
			success: function(obj){
				var msg = $.parseJSON(obj);
				if(msg.signin_status != "success")
				{
					sys_show_error("#login_status",msg.signin_msg);
				}
				else
				{
					sys_show_success("#login_status",msg.signin_msg,'/sys/home/');
				}
			}
		});
	});

});